unit Obs_cliente;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, clsEntidade, StdCtrls, Buttons, DB, DBClient, Grids, DBGrids, dbtables;

type
  TfrmObs_cliente = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    memObs: TMemo;
    btnFechar: TBitBtn;
    dbgSerasa: TDBGrid;
    CDSSerasa: TClientDataSet;
    CDSSerasaSER_CODIGO: TStringField;
    CDSSerasaSER_QTDE: TIntegerField;
    CDSSerasaSER_ANOTACAO: TStringField;
    CDSSerasaSER_DATAINI: TDateField;
    CDSSerasaSER_DATAFIM: TDateField;
    CDSSerasaSER_OCORRENCIA: TStringField;
    CDSSerasaSER_LOCAL: TStringField;
    dsSerasa: TDataSource;
    procedure btnFecharClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    ent_codigo: string;
  end;

var
  frmObs_cliente: TfrmObs_cliente;

implementation

uses clsSERASA, Dm, Biblio;

{$R *.DFM}

var
  entidade: TEntidade;

procedure TfrmObs_cliente.btnFecharClick(Sender: TObject);
begin
  close;
end;

procedure TfrmObs_cliente.FormActivate(Sender: TObject);
var
  Serasa: TSERASA;
  tq: TQuery;
begin
  entidade.Recuperar(ent_codigo);
  memObs.Text := entidade.Ent_Observacao;
  try
    CDSSerasa.Close;
    CDSSerasa.CreateDataSet;
    CDSSerasa.Open;

    tq := TQuery.Create(dmint);
    tq.DatabaseName := DmInt.Db.DatabaseName;
    tq.active := False;
    Serasa := TSERASA.Create;
    Serasa.Consultar(tq, strzero(ent_Codigo, 5));
    CDSSerasa.Close;
    CDSSerasa.CreateDataSet;
    CDSSerasa.Open;
    while not tq.Eof do begin
      CDSSerasa.Append;
      CDSSerasaSER_QTDE.AsInteger := tq.FieldByName('Ser_Qtde').AsInteger;
      CDSSerasaSER_ANOTACAO.AsString := tq.FieldBYName('Ser_Anotacao').AsString;
      CDSSerasaSER_DATAINI.AsDateTime := tq.FieldByName('Ser_DataIni').AsDateTime;
      CDSSerasaSER_DATAFIM.AsDateTime := tq.FieldByName('Ser_DataFim').AsDateTime;
      CDSSerasaSER_OCORRENCIA.AsString := tq.FieldByName('Ser_Ocorrencia').AsString;
      CDSSerasaSER_LOCAL.AsString := tq.FieldByName('Ser_Local').AsString;
      CDSSerasa.Post;
      tq.Next;
    end;
    CDSSerasa.First;
    Serasa.Free;
    tq.close;
    tq.free;
  except
  end;
end;

procedure TfrmObs_cliente.FormCreate(Sender: TObject);
begin
  entidade := Tentidade.Create;
end;

procedure TfrmObs_cliente.FormDestroy(Sender: TObject);
begin
  entidade.Free;
end;

end.

